<?php
class Class_manager extends Controller {

    function Class_manager() {
        parent::Controller();
        $this->load->model('mod_class_manager');
    }

    //======================function for load page master=====================//

    function index() {
        if($this->check_session()){
        $this->load->view('master');
        }else{
           redirect('admin/');
           exit();
        }
    }

    //========================function for loading page master page========================//

    function manager() {
        if($this->check_session()){
        $select_class['value_class'] = $this->mod_class_manager->select_class();
        $this->load->view('master', $select_class);
        $data['title'] = 'class manager';
        }else{
            redirect('admin/');
            exit();
        }
    }

    //============================function for adding new class========================//

    function add() {
        if($this->check_session()){
        $data['title'] = 'this is the add new page';
        $this->load->helper("mgpage");
        $this->form_validation->set_rules('txtclassname', 'ClassName', 'required|string|trim|max_length[50]');
       // $this->form_validation->set_rules('txtdetail', 'Description', 'required|trim|max_length[200]');
        if ($this->input->post('btn_submit')) {
            if ($this->form_validation->run() == false) {
                $this->load->view('master', $data);
            } else {
                $this->mod_class_manager->addclass();
                $this->session->set_userdata('addclass_ms', '<br/><dl id="system-message"><dd class="message message"><ul><li>Add Successful!</li></ul></dd></dl>');
                redirect('class_manager/manager');
            }
        } else {
            $this->load->view('class_manager/add');
        }
        }else{
            redirect('admin/');
            exit();
        }
    }

    //=========================this is function for deleted class======================//

    function delete() {
        if($this->check_session()){
        $this->mod_class_manager->delete();
        $this->session->set_userdata('delclass_ms', '<br/><dl id="system-message"><dd class="message message"><ul><li>Deleted Successful!</li></ul></dd></dl>');
        redirect('class_manager/manager');
        }else{
            redirect('admin/');
            exit();
        }
    }

    //======================this is function for select detail========================//

    function detail() {
        if($this->check_session()){
        $getdetail['detailget'] = $this->mod_class_manager->select_detail();
        $this->load->view('master', $getdetail);
        }else{
            redirect('admin/');
            exit();
        }
    }

    //===========================this is function for edit class====================//

    function edit() {
        if($this->check_session()){
        if ($this->input->post('btn_submit')) {
            $this->mod_class_manager->checkedit();
            $this->session->set_userdata('msedit', 'Edit successfully');
            $this->session->set_userdata('editclass_ms', '<br/><dl id="system-message"><dd class="message message"><ul><li>Edited Successful!</li></ul></dd></dl>');
            redirect('class_manager/manager');
        } else {
            $data['getresult'] = $this->mod_class_manager->selet_edit();
            $this->load->view('master', $data);
        }
        }else{
            redirect('admin/');
            exit();
        }
    }
    
    //========this is function for using checking session=============
    
     public function check_session() {
        if ($this->session->userdata('use_username')) {
            return true;
        } else {
            return false;
        }
    }

}